package com.cloudsigns.factorymanager2.engineering.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringInstallStatuBean;
import com.cloudsigns.factorymanager2.engineering.bean.MediaBean;
import com.cloudsigns.factorymanager2.engineering.bean.PublicationOrderDetailBean;
import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;


import java.util.ArrayList;
import java.util.List;

/**
 * Created by tony on 2018/5/12.
 */

public class TableLeftEngineeringInstallForManagerAdapter<T> extends BaseAdapter {
    private Context context;
    private List<T> mListData = new ArrayList<>();
    private String tag = "";

    private ItemClickListener itemClickListener;

    public TableLeftEngineeringInstallForManagerAdapter(Context context, String tag) {
        this.context = context;
        this.tag = tag;
    }


    public void setData(List<T> list) {
        mListData.clear();
        if (null != list) {
            mListData.addAll(list);
        }

    }

    public void setOnclickListerner(ItemClickListener clickListener) {
        this.itemClickListener = clickListener;
    }

    @Override
    public int getCount() {
        return mListData.size();
    }

    @Override
    public Object getItem(int position) {
        return mListData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_table_left_list, null);
            holder.tv_left = convertView.findViewById(R.id.tv_left);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (null != tag) {
            if (tag.equals("PatrolStatusTableForManagerActivity")) {

                MediaBean mediaBean = (MediaBean) mListData.get(position);
                holder.tv_left.setText(mediaBean.getMediaName());

            } else if (tag.equals("EngineeringInstallStatusTableForManagerActivity1")) {

                EngineeringInstallStatuBean engineeringInstallStatuBean = (EngineeringInstallStatuBean) mListData.get(position);
                holder.tv_left.setText(engineeringInstallStatuBean.getEngineeringName());

            } else if (tag.equals("PublicationStatusTableForManagerActivity2")) {
                MediaBean mediaBean = (MediaBean) mListData.get(position);
                holder.tv_left.setText(mediaBean.getMediaName());
                holder.tv_left.setTag(mediaBean);

                holder.tv_left.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if(null !=  itemClickListener)
                            itemClickListener.itemClick(view,position);
                    }
                });
            }
        }

        return convertView;
    }

    class ViewHolder {
        TextView tv_left;

    }
}
